<template>
  <div class="page-box">
    <div class="page-header">
      <div class="back" @click="goback">
        <el-icon><ArrowLeftBold /></el-icon>
      </div>
      <div class="title">商品详情</div>
    </div>

    <div class="content-box">
      <div class="detail-img">
        <img :src="detailData.picGoodsUrl" alt="商品图片" />
      </div>
      <div class="detail-info">
        <div class="detail-title">{{ detailData.name }}</div>
        <div class="detail-description">
          {{ detailData.description }}
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from "vue";
import { getGoodsDetail } from "@/api/modules/mobile";
import { useRoute, useRouter } from "vue-router";

const route = useRoute();
const router = useRouter();

const detailData = ref<any>({});

onMounted(async () => {
  const query = route.query;
  if (query.id) {
    const params = { id: query.id };
    const res = await getGoodsDetail(params);
    if (res) {
      detailData.value = res.data;
    }
  }
});

const goback = () => {
  router.go(-1);
};
</script>

<style lang="scss" scoped>
.page-box {
  position: relative;
  width: 100%;
  height: 100%;
  background-color: #f3f0f0;
  .page-header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 40px;
    background-color: #ffffff;
    border-bottom: 1px solid #333333;
    .back {
      position: absolute;
      top: 12px;
      left: 12px;
    }
    .title {
      font-size: 20px;
      font-weight: 500;
      color: #333333;
    }
  }
  .content-box {
    width: calc(100% - 56px);
    padding: 16px;
    margin: 16px auto;
    background-color: #ffffff;
    border-radius: 8px;
    box-shadow: 0 2px 5px 1px #33333350;
    .detail-img {
      width: 100%;
      height: 220px;
      overflow: hidden;
      background-color: #f5f5f5;
      border-radius: 8px;
      img {
        width: 100%;
        height: 100%;
        object-fit: cover;
      }
    }
    .detail-info {
      margin-top: 16px;
      .detail-title {
        margin-bottom: 12px;
        font-size: 20px;
        font-weight: bold;
        color: #333333;
      }
      .detail-description {
        font-size: 16px;
        line-height: 1.6;
        color: #666666;
      }
    }
  }
}
</style>
